Skip to content

fix: handle empty includes/excludes arrays in build config#3788

Open
JE4NVRG wants to merge 1 commit intoadaptlearning:masterfrom
JE4NVRG:fix/empty-build-includes-excludes
Open

fix: handle empty includes/excludes arrays in build config#3788
JE4NVRG wants to merge 1 commit intoadaptlearning:masterfrom
JE4NVRG:fix/empty-build-includes-excludes

Conversation

@JE4NVRG
Copy link
Copy Markdown

@JE4NVRG JE4NVRG commented Mar 30, 2026

Description

Fixes issue #3786 where empty arrays in build.excludes or build.includes cause build failures.

The Problem

Setting build.excludes or build.includes to an empty array [] in config.json causes unexpected build failures. An empty array should be equivalent to not specifying the property at all, but instead it silently breaks plugin filtering.

Root Cause

In helpers.js generateConfigData(), empty arrays pass the truthiness check and get propagated into grunt config:

if (buildConfig.includes) data.includes = ... // [] is truthy!
if (buildConfig.excludes) data.excludes = ... // [] is truthy!

This produces malformed regexes that match everything, breaking the build.

The Fix

Add .length checks so empty arrays are treated identically to undefined:

if (buildConfig.includes?.length) ...
if (buildConfig.excludes?.length) ...
if (buildConfig.productionExcludes?.length) ...

Testing

  • Tested with empty build.excludes: [] - build now works correctly
  • Tested with empty build.includes: [] - build now works correctly
  • Tested with populated arrays - existing behavior unchanged
  • Tested without specifying properties - existing behavior unchanged

Related Issue

Fixes #3786


Let me know if you need any changes! 🚀

Empty arrays are truthy in JavaScript, so checks like
`if (buildConfig.excludes)` pass even when the array has no entries.
This causes generateExcludedRegExp to produce `new RegExp('', 'i')`
which matches every file path, excluding all plugins from the build.

Add .length checks so empty arrays are treated the same as undefined.

Fixes adaptlearning#3786
@oliverfoster
Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Empty build.excludes or build.includes array breaks the build

2 participants